package mo.tags.stack;

public class L880 {

    public String decodeAtIndex(String s, int k) {
        long size = 0;
        int N = s.length();
        for (int i = 0; i < N; i++) {
            char c = s.charAt(i);
            if (Character.isDigit(c)) {
                size = size * (c - '0');
            } else {
                size++;
            }
        }
        for (int i = N-1; i >= 0; i--) {
            k = (int) (k % size);
            char c = s.charAt(i);
            if (k == 0 && !Character.isDigit(c)) {
                return c + "";
            }
            if (Character.isDigit(c)) {
                size = size / (c - '0');
            } else {
                size--;
            }
        }
        return null;
    }

}
